﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public enum E_Alignment_Type
{
    Up,
    Down,
    Left,
    Right,
    Center,
    Left_Up,
    Left_Down,
    Right_Up,
    Right_Down,
}

[System.Serializable]
/// <summary>
/// 该类 是用来表示位置 计算位置相关信息
/// </smmary>
public class CustomGUIPos
{
    //处理控件位置相关的内容
    //完成 分辨率自适应的相关计算

    //该位置信息 用来返回给外部 用于绘制控件
    private Rect pos = new Rect(0,0,100,100);
    //屏幕对齐方式
    public E_Alignment_Type screen_Alignment_Type = E_Alignment_Type.Center;
    //控件对齐方式
    public E_Alignment_Type control_Alignment_Type = E_Alignment_Type.Center;
    //偏移位置
    public Vector2 offset;
    //宽高
    public float width = 100;
    public float height = 50;
    //屏幕
    public Vector2 centerPos;
    private void CalcCenterPos()
    {
        switch (control_Alignment_Type)
        {
            case E_Alignment_Type.Up:
                {
                    centerPos.x = -width / 2;
                    centerPos.y = 0;
                    break;
                }
            case E_Alignment_Type.Down:
                {
                    centerPos.x = -width / 2;
                    centerPos.y = -height;
                    break;
                }
            case E_Alignment_Type.Left:
                {
                    centerPos.x = 0;
                    centerPos.y = -height/2;
                    break;
                }
            case E_Alignment_Type.Right:
                {
                    centerPos.x = -width;
                    centerPos.y = -height/2;
                    break;
                }
            case E_Alignment_Type.Center:
                {
                    centerPos.x = -width / 2;
                    centerPos.y = -height/2;
                    break;
                }
            case E_Alignment_Type.Left_Up:
                {
                    centerPos.x = 0;
                    centerPos.y = 0;
                    break;
                }
            case E_Alignment_Type.Left_Down:
                {
                    centerPos.x = 0;
                    centerPos.y = -height;
                    break;
                }
            case E_Alignment_Type.Right_Up:
                {
                    centerPos.x = -width;
                    centerPos.y = 0;
                    break;
                }
            case E_Alignment_Type.Right_Down:
                {
                    centerPos.x = -width;
                    centerPos.y = -height;
                    break;
                }
        }
    }
    private void CalcPos()
    {
        switch (screen_Alignment_Type)
        {
            case E_Alignment_Type.Up:
                {
                    pos.x = Screen.width / 2 + centerPos.x + offset.x;
                    pos.y = centerPos.y + offset.y;
                    break;
                }
            case E_Alignment_Type.Down:
                {
                    pos.x = Screen.width / 2 + centerPos.x + offset.x;
                    pos.y = Screen.height + centerPos.y - offset.y;
                    break;
                }
            case E_Alignment_Type.Left:
                {
                    pos.x = centerPos.x + offset.x;
                    pos.y = Screen.height/2 + centerPos.y + offset.y;
                    break;
                }
            case E_Alignment_Type.Right:
                {
                    pos.x =  Screen.width + centerPos.x + offset.x;
                    pos.y = Screen.height / 2 + centerPos.y + offset.y;
                    break;
                }
            case E_Alignment_Type.Center:
                {
                    pos.x = Screen.width / 2 + centerPos.x + offset.x;
                    pos.y = Screen.height / 2 + centerPos.y + offset.y;
                    break;
                }
            case E_Alignment_Type.Left_Up:
                {
                    pos.x = centerPos.x + offset.x;
                    pos.y = centerPos.y + offset.y;
                    break;
                }
            case E_Alignment_Type.Left_Down:
                {
                    pos.x = centerPos.x + offset.x;
                    pos.y = Screen.height + centerPos.y - offset.y;
                    break;
                }
            case E_Alignment_Type.Right_Up:
                {
                    pos.x = Screen.width + centerPos.x + offset.x;
                    pos.y = centerPos.y + offset.y;
                    break;
                }
            case E_Alignment_Type.Right_Down:
                {
                    pos.x = Screen.width + centerPos.x + offset.x;
                    pos.y = Screen.height + centerPos.y - offset.y;
                    break;
                }
        }
    }
    public Rect Pos
    {
        get
        {
            CalcCenterPos();
            CalcPos();
            pos.width = width;
            pos.height = height;

            return pos;
        }
    }
}
